#pragma once
#include<iostream>
#include<assert.h>
using namespace std;

namespace my
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin();
		iterator end();

		const_iterator begin() const;
		const_iterator end() const;

		string(const char* str = "");
		string(const string& s);
		//string& operator=(const string& s);
		string& operator=(string s);
		~string();

		size_t size() const;
		size_t capacity() const;
		void reserve(size_t n = 0);
		void clear();
		bool empty() const;

		char& operator[](size_t pos);
		const char& operator[] (size_t pos) const;
		char& back();
		char& front();

		void push_back(char c);
		string& append(const string& s);
		string& operator+=(char c);
		string& operator+=(const string& s);
		string& assign(const string& s);
		string& assign(size_t n, char c);
		string& insert(size_t pos, const string& s);
		string& insert(size_t pos, char c);
		string& erase(size_t pos = 0, size_t len = npos);
		string& replace(size_t pos, size_t len, const string& str);
		void swap(string& str);
		void pop_back();

		char* c_str();
		size_t find(const string& str, size_t pos = 0) const;
		size_t find(char c, size_t pos = 0) const;
		int compare(const string& str) const;
		
		string operator+(const string& s);
		string operator+(char c);
		bool operator<(const string& s);
		bool operator>(const string& s);
		bool operator<=(const string& s);
		bool operator>=(const string& s);
		bool operator==(const string& s);
		bool operator!=(const string& s);

	private:
		char* _str = nullptr;
		size_t _size = 0;
		size_t _capacity = 0;

		static const size_t npos;
	};
	ostream& operator<<(ostream& os, const string& str);
	istream& operator>>(istream& is, string& str);
	void swap(string& x, string& y);
};